﻿using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Windows.Forms;

namespace NFox.Pyeditor.Runtime
{

    public class ConsoleStream
    {

        private dynamic _console;
        private static Queue<string> _buffer;

        public static ConsoleStream Curr { get; private set; }

        public ConsoleStream(dynamic console)
        {
            _console = console;
            _buffer = new Queue<string>();
            Curr = this;
        }

        public static void Enqueue(string message)
        {
            _buffer.Enqueue(message);
        }

        public string read()
        {
            _console.IsRead = true;
            while (_buffer.Count == 0)
            {
                System.Windows.Forms.Application.DoEvents();
                Thread.Sleep(10);
            }
            string res = _buffer.Dequeue();
            return res;
        }

        public void write(string message)
        {
            _console.Write(message);
        }

    }


}
